Skip to content

[KernelGen][MThreads] Add feature_dropout Moore Threads specialized operator - #300

Open
Yukun-Cui wants to merge 2 commits into
flagos-ai:infra-cifrom
Yukun-Cui:pr/mthreads-feature_dropout
Open

[KernelGen][MThreads] Add feature_dropout Moore Threads specialized operator#300
Yukun-Cui wants to merge 2 commits into
flagos-ai:infra-cifrom
Yukun-Cui:pr/mthreads-feature_dropout

Conversation

@Yukun-Cui

@Yukun-Cui Yukun-Cui commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

[KernelGen][MThreads] Add feature_dropout Moore Threads specialized operator

Summary

Add a Moore Threads (MUSA) specialized Triton kernel for feature_dropout, overriding the generic implementation via runtime.replace_customized_ops(). The specialization uses three channel-keyed kernels: a scalar factor kernel for tiles aligned to one channel (feature_dropout_uniform_kernel), a straddle kernel for tiles that span channel boundaries (feature_dropout_straddle_kernel), and a per-element nibble-packed RNG kernel for the spatial == 1 case (feature_dropout_channel1_kernel) that cuts RNG cost by 8x while keeping per-element determinism.

Testing

  • Reused the existing upstream accuracy tests tests/test_feature_dropout.py (-m feature_dropout)
  • Validated against reference on the MUSA device; specialization confirmed active via the GEMS_MTHREADS FEATURE_DROPOUT debug log
  • Falls back to the generic implementation for unsupported dtype/device/shape (fp64/int64 not supported on Moore Threads hardware)

Performance

Compared against the generic FlagGems implementation on Moore Threads (MUSA).

feature_dropout

dtype Size Torch Latency (ms) Gems Latency (ms) Speedup
float16 64, 64 0.025480 0.004760 5.353x
float16 1024, 1024 0.025360 0.006200 4.090x
float16 4096, 4096 0.198140 0.075120 2.638x
float16 64, 512, 512 0.082280 0.073280 1.123x
float16 1024, 1024, 1024 3.271280 3.200120 1.022x
float32 64, 64 0.009920 0.006440 1.540x
float32 1024, 1024 0.030680 0.010840 2.830x
float32 4096, 4096 0.334560 0.135300 2.473x
float32 64, 512, 512 0.144040 0.134160 1.074x
float32 1024, 1024, 1024 6.597120 6.378320 1.034x
bfloat16 64, 64 0.010440 0.004920 2.122x
bfloat16 1024, 1024 0.025480 0.006240 4.083x
bfloat16 4096, 4096 0.199520 0.075200 2.653x
bfloat16 64, 512, 512 0.082320 0.074400 1.106x
bfloat16 1024, 1024, 1024 3.250960 3.200480 1.016x
Operator Arithmetic Mean Speedup
feature_dropout 2.28x

Files Changed

  • src/flag_gems/runtime/backend/_mthreads/ops/feature_dropout.py: Moore Threads Triton kernel + fallback
  • src/flag_gems/runtime/backend/_mthreads/ops/__init__.py: Register import and __all__

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | feature_dropout:mthreads

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

❌ On-demand test failed

Operator: | feature_dropout
Runner: mthreads
Backend: mthreads-musa520

The test failed to complete. Check the workflow run for details.

@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | feature_dropout:mthreads

@Dongxu-H

Copy link
Copy Markdown
Collaborator

LGTM

The in-place feature_dropout_ in the mthreads specialized module duplicated
the public fallback (which just calls feature_dropout then copy_). Remove
the specialized variant: torch.feature_dropout_ now dispatches to the
public implementation, which in turn reuses the mthreads-specialized
feature_dropout (non-in-place). Matches the pattern of backends that do
not specialize feature_dropout_ (e.g. nvidia).
@Dongxu-H

Copy link
Copy Markdown
Collaborator

/test | feature_dropout:mthreads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants